package com.second.app.proxy.main;

import com.second.app.proxy.*;

import java.math.BigDecimal;

/**
 * @Author GYZ
 * @Date 2023/9/18
 * <pre>
 *
 * </pre>
 */
public class Test {

    public static void main(String[] args) {


        Long productId= 123L;

        Product product = Product.builder()
                .productId(productId)
                .productName("红烧肉")
                .productPrice(BigDecimal.valueOf(28)).build();

        ProductServiceImpl target = new ProductServiceImpl();


        System.out.println("----------------静态代理--------------------");

        ProductServiceStaticProxy staticProxy = new ProductServiceStaticProxy(target);

        staticProxy.addProduct(product);

        staticProxy.getProductById(productId);

        System.out.println("----------------jdk动态代理--------------------");

        ProductService proxy = (ProductService)new JdkDynamicProxy(target).getProxy();

        proxy.addProduct(product);

        proxy.getProductById(productId);


        System.out.println("----------------cglib动态代理--------------------");

        ProductServiceImpl cglibDynamicProxy = (ProductServiceImpl) new CglibDynamicProxy(target).getProxy();

        cglibDynamicProxy.addProduct(product);

        cglibDynamicProxy.getProductById(productId);
    }
}
